<template>
	<view>
		<view class="container">
			
		<view class="list-cell b-b m-t" @click="inputShowModal()" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">修改手机号</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		
		<view class="list-cell b-b m-t" @click="passWordModal()" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">修改密码</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		
		
		<neil-modal 
			:show="inputShow" 
			@close="cancel" 
			title="编辑" 
			@cancel="cancel" 
			@confirm="confirm">
			<input v-model="inputContent" style="margin:20upx" placeholder="请输入手机号" maxlength="11"/>
		</neil-modal>
		
		<neil-modal
			:show="passWordShow" 
			@close="cancel" 
			title="密码修改" 
			@cancel="cancel" 
			@confirm="updatePassword">
			<input v-model="passWord.upwd" style="margin:20upx;height:60upx;" placeholder="请输入旧密码" maxlength="16"/>
			<hr style="background-color:#eee;height:1upx;border:none;">
			<input v-model="passWord.newupwd" style="margin:20upx;height:60upx;" placeholder="请输入新密码" maxlength="16"/>
		</neil-modal>

		
	</view>
	</view>
</template>

<script>
	import neilModal from '@/components/neil-modal/neil-modal.vue';
	import {  
	    mapState,  
	    mapMutations  
	} from 'vuex';  
	export default {
		components: {
			neilModal
		},
		data() {
			return {
				inputShow: false,
				inputContent:'',
				passWordShow:false,
				passWord:{
					upwd:'',
					newupwd:''
				}
				
				};
		},
		computed:{
			...mapState(['userInfo']),
		},
		onLoad(){
			console.log(this.inputContent);
		},
		methods: {
			cancel() {
				this.inputShow = false
				this.passWordShow = false
			},
			inputShowModal() {
				this.inputShow = true
				this.inputContent=this.userInfo.uphone;
			},
			passWordModal(){
				this.passWordShow = true
				this.passWord= Object.assign({},{
					upwd:'',
					newupwd:''
				})
				console.log(this.passWord);
			},
			confirm() {
				const that = this
				if (!(/^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(that.inputContent))) {
					uni.showToast({
						title:'请输入正确手机号！',
						icon:'none'
					})
					return;
				}
				
				that.$api.updatePhone({uphone:that.inputContent}).then((res)=>{
					if(res.data.stastus==200){
						that.userInfo.uphone=that.inputContent;
						that.$store.commit('login', that.userInfo)
						uni.showToast({
						    title: res.data.msg,
							mask:true
						});
					}
				})
			},
			updatePassword(){
				console.log(this.passWord);
				let data=this.passWord;
				if (data.upwd.length < 6) {
					uni.showToast({
						icon: 'none',
						title: '旧密码最短为6位数'
					});
					return;
				}
				if (data.newupwd.length < 6) {
					uni.showToast({
						icon: 'none',
						title: '新密码最短为6位数'
					});
					return;
				}
				this.$api.updatePassWord(data).then((res)=>{
					if(res.data.stastus==200){
						uni.showToast({
						    title: res.data.msg,
							mask:true
						});
					}
				})
				
			},
			
			
		}
	}
</script>

<style lang="scss">
	page{
		background: $page-color-base;
	}
	
	page{
		background: $page-color-base;
	}
	.list-cell{
		display:flex;
		align-items:baseline;
		padding: 20upx $page-row-spacing;
		line-height:60upx;
		position:relative;
		background: #fff;
		justify-content: center;
		&.log-out-btn{
			margin-top: 40upx;
			.cell-tit{
				color: $uni-color-primary;
				text-align: center;
				margin-right: 0;
			}
		}
		&.cell-hover{
			background:#fafafa;
		}
		&.b-b:after{
			left: 30upx;
		}
		&.m-t{
			margin-top: 16upx; 
		}
		.cell-more{
			align-self: baseline;
			font-size:$font-lg;
			color:$font-color-light;
			margin-left:10upx;
		}
		.cell-tit{
			flex: 1;
			font-size: $font-base + 2upx;
			color: $font-color-dark;
			margin-right:10upx;
		}
		.cell-tip{
			font-size: $font-base;
			color: $font-color-light;
		}
		switch{
			transform: translateX(16upx) scale(.84);
		}
	}


</style>
